<template>
  <div class="app-container">
    <el-form :model="searchForm" :inline="true">
      <el-row>
        <el-col :span="23">
          <el-form-item>
            <el-input
              v-model="searchForm.sampleNo"
              style="width: 170px"
              placeholder="请录入样品编号"
            />
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="searchForm.sampStatus"
              clearable
              style="width: 170px"
              placeholder="请选择库存状态"
            >
              <el-option label="已入库" :value="6" />
              <!-- <el-option label="部分出库" :value="7" /> -->
              <el-option label="已出库" :value="8" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="searchForm.fileType"
              style="width: 170px"
              placeholder="请选择交接单类别"
              clearable
            >
              <el-option
                v-for="item in labelSelect"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="searchForm.applyUserId"
              style="width: 170px"
              placeholder="请选择领样人"
              clearable
            >
              <el-option
                v-for="item in applyUserSelect"
                :key="item.applyUserId"
                :label="item.applyUser"
                :value="item.applyUserId"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-select
              v-model="searchForm.sendUser"
              style="width: 170px"
              placeholder="请选择送样人"
              clearable
            >
              <el-option
                v-for="(item, index) in sendUserSelect"
                :key="index"
                :label="item.sendUser"
                :value="item.sendUser"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="signDate">
            <el-date-picker
              v-model="searchForm.date"
              clearable
              type="daterange"
              value-format="yyyy-MM-dd"
              start-placeholder="入库开始日期"
              end-placeholder="入库结束日期"
              style="width: 320px"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              class="iconfont icon-chaxun1"
              size="small"
              @click="handleSearch"
            >
              查询</el-button
            >
            <el-button
              type="primary"
              class="iconfont icon-fanhui"
              size="small"
              @click="goBack"
            >
              返回</el-button
            >
            <!-- <el-button type="primary" icon="el-icon-download" @click="handleDownlond"> 交接单导出</el-button> -->
            <el-button type="text" icon="el-icon-printer" @click="tabPrints" style="padding-left: 30px;">转码样品标签打印</el-button>
            <el-button type="text" icon="el-icon-download" @click="handleDownlond">交接单下载</el-button>
            <el-button type="text" icon="el-icon-refresh" @click="handleSearch">刷新</el-button>
            <template v-if="showTitle">
              <el-row style="text-align:center;font-size:14px;margin-top: 10px;">
                <el-col :span="24">Web打印服务C-Lodop软件未安装启动，请<a href="#" style="color:red" @click="fileDownLoad">点击这里</a>下载执行安装</el-col>
              </el-row>
<!--              <el-row style="text-align:center;font-size:14px;padding-top:3px;">-->
<!--                <el-col :span="24">(若此前已安装过，<a href="#" style="color:red" @click="tabPrint">可点这里直接再次启动</a>），成功后请刷新本页面。</el-col>-->
<!--              </el-row>-->
            </template>
            <template v-else>
              <div style="visibility: hidden;">信息提示</div>
            </template>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div>
      <el-table
        ref="stockTable"
        stripe
        border
        :data="stockData"
        class="table-item"
        highlight-current-row
        :header-cell-style="{ background: '#ECF3FC' }"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        @select="handleSelect"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span> 暂无审核信息 </span>
            </div>
          </div>
        </template>
        <el-table-column
          type="selection"
          width="55"
          :selectable="checkSelectable"
          align="center"
        />
        <el-table-column
          type="index"
          fixed="left"
          width="55"
          align="center"
          label="序号"
        />
        <el-table-column
          prop="sampleNo"
          label="样品编号"
          fixed="left"
          width="150px"
          align="center"
        />
        <el-table-column
          prop="sampleNumber"
          label="来样送检样品编号"
          fixed="left"
          width="150px"
          align="center"
        />
        <el-table-column
          prop="sampleCode"
          label="样品转码编号"
          fixed="left"
          width="150px"
          align="center"
        />
        <el-table-column
          prop="jobId"
          label="任务单号"
          width="130px"
          align="center"
        />
        <el-table-column
          prop="projectName"
          label="项目名称"
          min-width="150px"
          align="center"
        />
        <el-table-column prop="secdClassName" label="检测类别" align="center" />
        <el-table-column
          prop="factorPoint"
          label="采样点位"
          min-width="100px"
          align="center"
        />
        <el-table-column prop="factorNameTwo" label="检测因子" width="180" align="center">
          <template slot-scope="row">
            <el-tooltip effect="dark" placement="top">
              <div slot="content" style="max-width: 400px">{{ row.row.factorNameTwo}}</div>
              <div class="apostrophe">
                <span>{{ row.row.factorNameTwo}}</span>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="collectUser" label="采样人" align="center" />
        <el-table-column
          prop="applyUser"
          label="领样人"
          width="100px"
          align="center"
        />
        <el-table-column
          prop="storeLocation"
          label="存放位置"
          min-width="100px"
          align="center"
        />
        <el-table-column
          prop="inspectionName"
          label="受检单位"
          min-width="120px"
          align="center"
        />

        <el-table-column label="样品状态" align="center">
          <template slot-scope="{ row }">
            <el-tag :type="row.sampStatus | statusQualityFilter">
              {{ STOCK_STATUS[row.sampStatus] }}
            </el-tag>
          </template>
        </el-table-column>

        <el-table-column
          prop="storeTime"
          label="入库时间"
          width="160"
          align="center"
        />
        <el-table-column fixed="right" align="center" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetail(scope.row)">
              查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="float: right">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pageSize"
        @pagination="handleSearch"
      />
    </div>

    <el-dialog
      :title="currentSample + '-详情'"
      :visible.sync="sampleVisible"
      width="85%"
      center
      top="5vh"
    >
      <el-form
        :model="sampleDetailForm"
        label-width="180px"
        label-position="right"
      >
        <el-card style="margin-top: 5px; padding-bottom: 20px">
          <div slot="header" class="clearfix">
            <div
              style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
            />
            <span>基础信息</span>
          </div>
          <el-col :span="16" style="height: 32px">
            <el-form-item label-width="100" label="检测因子:">
              <span class="showTile">{{ sampleDetailForm.factorName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="height: 32px">
            <el-form-item label-width="100" label="点位:">
              <span class="showTile">{{ sampleDetailForm.factorPoint }}</span>
            </el-form-item>
          </el-col>
          <!--动态二级类别信息-->
        </el-card>
        <el-card
          v-for="item in sampleSecInfo"
          :key="item.groupKey"
          style="margin-top: 5px; padding-bottom: 20px"
        >
          <div
            v-if="item.groupName && item.groupName != ''"
            slot="header"
            class="clearfix"
          >
            <div
              style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
            />
            <span>{{ item.groupName }}</span>
          </div>
          <el-col
            v-for="(sitem, index) in item.params"
            :key="index"
            :span="8"
            style="height: 32px"
          >
            <el-form-item label-width="100">
              <span slot="label">{{ sitem.name }}:</span>
              <span class="showTile">{{
                sitem.value ? sitem.value.toString() : ""
              }}</span>
            </el-form-item>
          </el-col>
        </el-card>

        <el-card
          v-if="sampleDataInfo && sampleDataInfo.length > 0"
          style="margin-top: 5px"
        >
          <div slot="header" class="clearfix">
            <div
              style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
            />
            <span>现场检测因子信息</span>
          </div>
          <el-table :data="sampleDataInfo" stripe>
            <el-table-column prop="factorName" label="检测因子项目" />
            <el-table-column label="因子结果集">
              <template slot-scope="{ row }">
                <template v-if="row.measuredForm">
                  {{
                    "第一值: " +
                    row.measuredForm.firstVal +
                    " 第二值: " +
                    row.measuredForm.secondVal +
                    " 均值: " +
                    row.measuredForm.avgVal
                  }}
                </template>
                <template v-else>
                  {{ row.factorData ? row.factorData : "" }}
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="checkEquipment" label="检测仪器">
              <template slot-scope="{ row }">
                {{
                  row.checkEquipment && row.checkEquipment.length > 0
                    ? row.checkEquipment.replaceAll("^_^", " ")
                    : ""
                }}
              </template>
            </el-table-column>
            <el-table-column prop="theoreticalVal" label="理论值" />
            <el-table-column prop="groundConditions" label="测定值" />
          </el-table>
        </el-card>

        <el-card style="margin-top: 5px">
          <div slot="header" class="clearfix">
            <div
              style="
                width: 3px;
                margin: auto 3px;
                height: 20px;
                background-color: steelblue;
              "
            />
            <span>现场信息</span>
          </div>
          <el-col :span="12">
            <el-form-item label-width="100" label="采样地址:">
              <span class="showTile">{{
                sampleDetailForm.sampleDataVo.collectLocation
              }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="100" label="采样日期:">
              <span class="showTile">{{
                sampleDetailForm.sampleDataVo.collectDate
              }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label-width="100" label="现场图片:">
              <div
                v-if="sampleImageList && sampleImageList.length > 0"
                class="demo-image__lazy"
              >
                <el-image
                  v-for="(url, index) in sampleImageList"
                  :key="index"
                  :src="url"
                  :preview-src-list="sampleImageList"
                  style="width: 100px; height: 100px; margin-left: 10px"
                />
              </div>
            </el-form-item>
          </el-col>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="sampleVisible = false">关 闭</el-button>
      </div>
    </el-dialog>

    <el-dialog title="交接单下载" :visible.sync="downVisible" center>
      <div style="width: 500px; margin: 0 auto">
        <el-form :model="recordForm" label-width="130px">
          <el-form-item label="任务单号:">
            <el-input
              v-model="recordForm.taskId"
              placeholder="请录入任务单号"
              style="width: 300px"
            />
          </el-form-item>
          <el-form-item label="检测对象:">
            <el-select
              v-model="recordForm.classId"
              clearable
              style="width: 300px"
              filterable
              placeholder="检测对象"
              @change="findSecClass"
            >
              <el-option
                v-for="item in classArray"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="检测类别:">
            <el-select
              v-model="recordForm.secClassId"
              clearable
              style="width: 300px"
              filterable
              placeholder="检测类别"
            >
              <el-option
                v-for="item in secClassArray"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="采样信息记录时间:">
            <el-date-picker
              v-model="recordForm.sampleDate"
              type="date"
              placeholder="采样信息记录时间"
              value-format="yyyy-MM-dd"
              style="width: 300px"
            />
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="downVisible = false">取消</el-button>
        <el-button type="primary" @click="confirmDownload">确认</el-button>
      </div>
    </el-dialog>
    <el-dialog :title="addTitle" :visible.sync="adddVisible" width="85%">
      <el-table :data="gridData" @selection-change="dialogFactorChange">
        <el-table-column
          property="className"
          type="selection"
          width="55"
          label="检测类别"
        />
        <el-table-column property="className" label="检测类别" />
        <el-table-column property="factorName" label="检测因子" />
        <el-table-column property="standardNo" label="标准号" />
        <el-table-column property="standardName" label="标准名称" />
        <el-table-column property="analysisMethod" label="分析方法" />
        <el-table-column property="factorPoint" label="采样点位" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="adddVisible = false">取 消</el-button>
        <el-button type="primary" @click="adddVisibleComit">确 认</el-button>
      </div>
    </el-dialog>

    <div style="overflow: auto;opacity:0;">
      <div id="labelPrint" ref="labelPrint" style="margin: 0;padding: 5px; ">
        <div
          v-for="item in printList"
          :key="item.sampItemId"
          style="width: 60mm;height: 40mm;margin: 0; padding: 0px; font-size:12px;;"
        >
          <div style="padding-left: 10px;padding-top:6px;display: flex;">
            <div style="padding: 0px;line-height: 4mm;">受检单位:</div>
            <div style="padding-left: 10px;line-height: 4mm;">{{ item.inspectionName }}</div>
          </div>
          <div style="padding-left: 10px;display: flex;">
            <div style="padding:  0px;line-height: 4mm;">样品类别:</div>
            <div style="padding-left: 10px;line-height: 4mm;">{{ item.secdClassName }}</div>
          </div>
          <div style="padding-left: 10px;display: flex;">
            <div style="padding:  0px;line-height: 4mm;">检测因子:</div>
            <div style="padding-left: 10px;line-height: 4mm;">{{ item.factorName }}</div>
          </div>
          <div style="text-align: center; font-size: 12px;">
            <barcode :value="item.sampleCode" :options="barcode_option" tag="svg" />
          </div>
          <div style="padding-left: 10px;display: flex;">
            <div style="padding:  0px;line-height: 3mm;width: 8mm">点位:</div>
            <div style="padding:  0px;line-height: 3mm;width: 29mm;text-align:center;">{{ item.factorPoint }}</div>
          </div>
          <div style="padding-left: 10px;display: flex;">
            <div style="padding:  0px;line-height: 3mm;">状态:</div>
            <div style="padding-left: 10px;line-height: 4mm;">□未检 □在检 □已检</div>
          </div>
          <div style="padding-left: 10px;display: flex;">
            <div style="padding:  0px;line-height: 3mm;width: 14mm">日期:</div>
            <div style="padding:  0px;line-height: 3mm;width: 14mm">&nbsp;</div>
            <div style="padding:  0px;line-height: 3mm;width: 14mm">采样人:</div>
            <div style="padding:  0px;line-height: 3mm;width: 14mm">&nbsp;</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as stockServer from "@/api/stock";
import * as dictServer from "@/api/dict";
import { parseTime } from "@/utils";
import Pagination from "@/components/Pagination";
import { getLodop } from '@/utils/LodopFuncs' // Secondary package based on el-pagination
const STOCK_STATUS = {
  0: "待采样",
  1: "已采样",
  2: "待组长审核",
  3: "待负责人审核",
  4: "审核通过",
  5: "审核失败",
  6: "已入库",
  7: "部分出库",
  8: "已出库",
  9: "入库中",
  10: "待复核",
};
export default {
  components: { Pagination },
  filters: {
    statusQualityFilter(status) {
      const statusMap = {
        6: "",
        7: "success",
        8: "success",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      STOCK_STATUS,
      stockData: [],
      sampleNOsList: [],
      labelSelect: [
        {
          id: 1,
          name: "水模板",
        },
        {
          id: 2,
          name: "无组织废气模板",
        },
        {
          id: 3,
          name: "有组织废气模板",
        },
        {
          id: 4,
          name: "固废土壤模板",
        },
      ],
      applyUserSelect: [],
      sendUserSelect: [],
      gridData: [],
      searchForm: {
        sampTaskId: "",
        sampleNo: "",
        sampStatus: "",
        date: "",
        pageNumber: 1,
        pageSize: 10,
      },
      total: 0,
      addTitle: "新增平行样",
      adddVisible: false,
      approveVisible: false,
      sampleVisible: false,
      addObj: {
        sampleId: "",
        sampleTaskId: "",
        type: "",
        number: "",
        jobPlanFactorIds: "",
        groups: [],
      },
      sampleDetailForm: {
        factorName: "",
        factorPoint: "",
        secdClassName: "",
        factorDataVos: [],
        sampleDataVo: {
          collectDate: "",
          collectLocation: "",
          imageList: [],
          sampleData: [],
          specialNote: "",
        },
        sampleJobVo: {
          projectName: "",
          jobRemark: "",
        },
      },
      currentSample: "",
      approveForm: {
        sampleNo: "",
        auditFlag: "1",
        auditReason: "",
      },
      sampleImage: "",
      sampleImageList: [],
      multipleSelection: [],
      factorMultipleSelection: [],
      downVisible: false,
      recordForm: {
        taskId: "",
        classId: "",
        secClassId: "",
        sampleDate: "",
      },
      classArray: [],
      secClassArray: [],
      sampleDetails: [],
      sampleDataInfo: [],
      sampleSecInfo: [],
      currentSelectionRow: {
        jobId: "",
        secdClassName: "",
        storeData: "",
      },

      printList: [],
      barcode_option: {
        format: 'CODE128',
        displayValue: true, // 是否默认显示条形码数据
        background: 'rgba(255,255,255,.0)', // 条形码背景颜色
        width: '1.3px', // 单个条形码的宽度
        fontOptions: 'bold',
        height: '30mm',
        fontSize: '12px', // 字体大小
        textMargin: 0,
        font: '12px/1.5 arial,"黑体"',
        textAlign: 'center', // 设置文本的水平对齐方式
        margin: 5
      },
      showTitle: false
    };
  },
  created() {
    if (this.$route.params.sampTaskId) {
      this.searchForm.sampTaskId = this.$route.params.sampTaskId;
      this.getClassList();
      this.handleSearch();
    }
  },
  methods: {
    adddVisibleComit() {
      this.addObj.sampTaskId = this.$route.params.sampTaskId;
      this.addObj.sampleNo = this.multipleSelection[0].sampItemId;
      console.log(this.factorMultipleSelection);
      // stockServer.addQualityControl(this.searchForm).then(res => {
      //     is.code ==f (re= 200 && res.result) {
      //       this.stockData = res.result.records.map(i => {
      //         const sData = parseTime(i.storeTime, '{y}-{m}-{d}')
      //         this.$set(i, 'storeData', sData)
      //         return i
      //       }) || []
      //       this.total = res.result.total
      //     }
      //   })
      // }
    },
    handleSearch() {
      if (this.searchForm.jobId !== "") {
        this.clearSelectionRow();
        stockServer.getSamplesBySampTaskId(this.searchForm).then((res) => {
          if (res.code === 200 && res.result) {
            this.stockData =
              res.result.records.map((i) => {
                const sData = parseTime(i.storeTime, "{y}-{m}-{d}");
                this.$set(i, "storeData", sData);
                return i;
              }) || [];
            this.total = res.result.total;
            // let classnameArray = res.result.records.map((item) => {
            //   const classArr = {
            //     secdClassName: item.secdClassName,
            //     secdClassId: item.secdClassId,
            //   };
            //   return classArr;
            // });
            // let obj = {};
            // classnameArray = classnameArray.reduce((newArr, next) => {
            //   obj[next.secdClassId]
            //     ? ""
            //     : (obj[next.secdClassId] = true && newArr.push(next));
            //   return newArr;
            // }, []);
            // // const value = new Set(classnameArray);
            // this.labelSelect = classnameArray;
            let applyArray = res.result.records.map((item) => {
              const appArr = {
                applyUser: item.applyUser,
                applyUserId: item.applyUserId,
              };
              return appArr;
            });
            let appObj = {};
            applyArray = applyArray.reduce((newArr, next) => {
              appObj[next.applyUserId]
                ? ""
                : (appObj[next.applyUserId] = true && newArr.push(next));
              return newArr;
            }, []);
            this.applyUserSelect = applyArray;
            let sendArray = res.result.records.map((item) => {
              const sendArr = {
                sendUser: item.sendUser,
                // applyUserId: item.applyUserId,
              };
              return sendArr;
            });
            let sendObj = {};
            sendArray = sendArray.reduce((newArr, next) => {
              sendObj[next.sendUser]
                ? ""
                : (sendObj[next.sendUser] = true && newArr.push(next));
              return newArr;
            }, []);
            this.sendUserSelect = sendArray;
          }
        });
      }
    },

    handleDetail(row) {
      // 获取数据
      this.currentSample = row.sampleNo;
      this.sampleImageList = [];
      this.sampleDataInfo = [];
      this.sampleSecInfo = [];
      this.sampleImage = "";
      var baseUrl = this.$store.getters.sysBaseUrl + "/cyImg/";
      console.log(baseUrl);
      stockServer.getSampleDataBySampItemId(row.sampItemId).then((res) => {
        if (res.code === 200 && res.result) {
          this.sampleDetailForm = res.result || {};
          this.$nextTick(() => {
            // 提取图片
            this.sampleImageList = res.result.sampleDataVo.imageList.map(
              (i) => {
                return baseUrl + i;
              }
            );
            // 二级类别
            this.sampleSecInfo = res.result.sampleDataVo.sampleData || [];

            // 因子
            var nfactorDataVos =
              res.result.factorDataVos.filter((i) => i.dataEntryStep === "1") ||
              [];
            // 因子
            this.sampleDataInfo = nfactorDataVos.map((i) => {
              if (i.measuredFormVal && i.measuredFormVal.length > 0) {
                this.$set(i, "measuredForm", JSON.parse(i.measuredFormVal));
              }
              return i;
            });
          });
          this.sampleVisible = true;
        }
      });

      // stockServer.getSampleDetailBySampItemId(row.sampleNo).then(res => {
      //   if (res.code === 200) {
      //     this.sampleForm = res.result || {}
      //   }
      //   this.sampleVisible = true
      // })
      // 封装展示数据
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      this.sampleNOsList = val.map((item) => {
        return item.sampleNo;
      });
    },
    dialogFactorChange(val) {
      this.factorMultipleSelection = val;
    },
    handleCommand(v) {
      console.log(v, this.multipleSelection);
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        const params = {
          sampleId: this.multipleSelection[0].sampItemId,
          secdClassId: this.multipleSelection[0].secdClassId,
          type: 1,
          number: [],
        };

        stockServer.getFactorsBySampleId(params).then((res) => {
          if (res.code === 200 && res.result) {
            console.log(res);
            this.gridData = res.result;
            this.adddVisible = true;
          }
        });
        if (v == "新增密码样" && this.multipleSelection.length > 1) {
          this.$message.error("错误提示：新增密码样只可选择一个样品!");
        } else if (v == "新增密码样" && this.multipleSelection.length == 1) {
          this.addTitle = "新增密码样";
        }
        if (v == "新增平行样") {
          this.addTitle = "新增平行样";
        }
        if (v == "新增全程序空白样") {
        }
        // const samples = this.multipleSelection.map(i => {
        //   return i.sampleNo
        // })
        // const url = '/api/word/downLoadHandover?secdClassId=' + this.multipleSelection[0].secdClassId + '&sampleNos=' + samples.toString()
        // window.open(url)
      } else {
        this.$message.warning("至少选择一条记录");
      }
    },
    handleDownlond() {
      const sampStatus = this.searchForm.sampStatus || "";
      const sampleNo = this.searchForm.sampleNo || "";
      const startDate = this.searchForm.date[0] || "";
      const endDate = this.searchForm.date[1] || "";
      const fileType = this.searchForm.fileType || "";
      const sendUser = this.searchForm.sendUser || "";
      const applyUserId = this.searchForm.applyUserId || "";
      const data = {
        sampTaskId: this.$route.params.sampTaskId,
        sampStatus: this.searchForm.sampStatus,
        sampleNo: this.searchForm.sampleNo,
        type:
          this.searchForm.sampStatus == "6"
            ? 1
            : "" || this.searchForm.sampStatus == "7"
            ? 2
            : "",
        startDate: this.searchForm.date[0],
        endDate: this.searchForm.date[1],
        fileType: this.searchForm.fileType,
        sendUser: this.searchForm.sendUser,
        applyUserId: this.searchForm.applyUserId,
        sampleNOs: this.sampleNOsList,
      };
      const sampleNos = this.sampleNOsList || [];
      const type =
        this.searchForm.sampStatus == "6"
          ? 1
          : "" || this.searchForm.sampStatus == "7"
          ? 2
          : "";
      const id = this.$route.params.sampTaskId;
      const url =
        "/api/word/downLoadHandover1?sampTaskId=" +
        id +
        "&sampleNos=" +
        sampleNos +
        "&sampStatus=" +
        sampStatus +
        "&sampleNo=" +
        sampleNo +
        "&type=" +
        type +
        "&startDate=" +
        startDate +
        "&endDate=" +
        endDate +
        "&fileType=" +
        fileType +
        "&sendUser=" +
        sendUser +
        "&applyUserId=" +
        applyUserId;
      window.open(url);
      // stockServer.doDownLoadHandover(data).then((res) => {
      //   if (res.code === 200 && res.result) {
      //   const link = document.createElement('a') // 创建a标签
      //   const blo = new Blob([res],  {type: `application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8`}) // 设置下载格式
      //   link.style.display = 'none'
      //   const url = window.URL.createObjectURL(blo)
      //   link.href = url
      //   link.setAttribute('download', row.report_name)
      //   document.body.appendChild(link)
      //   link.click() // 触发下载
      //   window.URL.revokeObjectURL(url) // 释放掉blob对象
      //   document.body.removeChild(link)
      //   }
      // });
    },
    getClassList() {
      dictServer.findFstClasses().then((res) => {
        this.classArray = res.result || [];
      });
    },
    findSecClass(val) {
      this.recordForm.secClassId = "";
      dictServer.findSecdClassByClassId(val).then((res) => {
        this.secClassArray = res.result || [];
      });
    },
    confirmDownload() {
      if (
        this.recordForm.taskId &&
        this.recordForm.secClassId &&
        this.recordForm.sampleDate
      ) {
        const url =
          "/api/word/downLoadHandover?taskId=" +
          this.recordForm.taskId +
          "&secdClassId=" +
          this.recordForm.secClassId +
          "&sampleDate=" +
          this.recordForm.sampleDate;
        window.open(url);
        this.downVisible = false;
      } else {
        this.$message.warning("任务单号和检测类别不能为空");
      }
    },
    handleSelect(selection, row) {
      if (selection.length > 0) {
        this.currentSelectionRow.jobId = row.jobId;
        this.currentSelectionRow.secdClassName = row.secdClassName;
        this.currentSelectionRow.storeData = row.storeData;
      } else {
        this.clearSelectionRow();
      }
    },
    clearSelectionRow() {
      this.currentSelectionRow = {
        jobId: "",
        secdClassName: "",
        storeData: "",
      };
    },
    checkRow(item) {
      if (
        !this.currentSelectionRow.jobId ||
        this.currentSelectionRow.jobId === ""
      ) {
        return true;
      }
      if (
        item.jobId === this.currentSelectionRow.jobId &&
        item.secdClassName === this.currentSelectionRow.secdClassName &&
        item.storeData === this.currentSelectionRow.storeData
      ) {
        return true;
      }
      return false;
    },
    checkSelectable(row) {
      return this.checkRow(row);
    },
    goBack() {
      this.$router.back();
    },

    // 转码样品标签打印
    tabPrints() {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        this.printList = this.multipleSelection
        this.$nextTick(() => {
          this.tagPrints()
        })
      } else {
        this.$message.info('最少选择一条记录信息')
      }
    },

    tagPrints() {
      const LODOP = getLodop()
      console.log(LODOP);
      setTimeout(() => {
        this.$nextTick(() => {
          if (LODOP !== undefined) {
            LODOP.PRINT_INIT('标签')
            LODOP.ADD_PRINT_HTM(0, 0, '60mm', '40mm',
              document.getElementById('labelPrint').innerHTML)
            LODOP.SET_PRINT_MODE('TRYLINKPRINTER_NOALERT', true)// 这个语句设置网络共享打印机连接不通时是否提示一下
            LODOP.PREVIEW()
          }else {
            // 显示提示信息
            this.showTitle = true
            // this.$print(this.$refs.labelPrint)
          }
        })
      }, 1000)
    },
    fileDownLoad() {
      var url = this.$store.getters.sysBaseUrl + '/downLoad/CLodop_Setup_for_Win64NT_4.159EN.exe'
      window.open(url)
    }
  },
};
</script>

<style scoped lang="scss" type="text/scss">
.detail-continer{
  padding: 18px;
  background-color: #fff;
  margin:8px 10px;
  min-height: calc(100vh - 130px);
  border-radius: 5px;
}
.footer{
  height: 100px;
  width: 100%;
  bottom: 10px;
  font-size: 14px;
}
::v-deep .el-card .el-card__header {
  padding: 5px 20px;
  background: #F3F2F2;
}
.block-flex {
  position: relative;
  display: flex;
  &>div{
    border: 1px solid #B7B7B7;
    width: 100px;
    margin: 0;
    line-height: 30px;
    text-align: center;
  }
  &>div:first-child {
    background: #B7B7B7;
  }
}
.card-left {
  width: 100%;
  min-height: 200px;
  max-height: 400px;
}
.card-right {
  width: 100%;
  min-height: 200px;
  max-height: 400px;
}
.el-card {
  overflow: auto;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}
.el-icon-arrow-down {
  font-size: 12px;
}
.apostrophe{
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
</style>
